<?php

namespace App\Admin\Actions;

use Encore\Admin\Actions\Action;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class CustomerImport extends Action
{
    protected $selector = '.customer-import';


    public function handle(Request $request)
    {
        // 下面的代码获取到上传的文件，然后使用`maatwebsite/excel`等包来处理上传你的文件，保存到数据库

         Excel::import(new \App\Imports\CustomerImport(), $request->file('file'));
        return $this->response()->success('导入完成！')->refresh();
    }

    public function form()
    {
        $this->file('file', '请选择文件');
    }
    public function html()
    {
        return <<<HTML
        <a class="btn btn-sm btn-default customer-import">导入客户数据</a>
HTML;
    }
}
